<?php

/*
*	Comments DAO
*/

include_once('framework/DataAccessObject.php');

class CommentsDAO extends DataAccessObject
{
	function addComment($photoId, $name, $comment, $email, $url)
	{
			return $this->db->execute("INSERT INTO comments VALUES (?, DEFAULT, DEFAULT, ?, ?, ?, ?)", array($photoId, $name, $email, $url, $comment));
	}

	function getComments($photoId)
	{
		return $this->db->executeSet("SELECT comment, submit_date, name FROM comments WHERE id=? AND valid!=0 ORDER BY submit_date DESC", array($photoId));
	}

	function getAllComments($name)
	{
		return $this->db->executeSet("SELECT id, comment, submit_date FROM comments WHERE name=? ORDER BY submit_date DESC", array($name));
	}

	function getPendingComments($valid)
	{
		return $this->db->executeSet("SELECT id, name, comment, submit_date FROM comments WHERE valid=? ORDER BY id DESC",array($valid));
	}

	function activateComment($photoId, $submit_date)
	{
		return $this->db->execute("UPDATE comments SET valid='1' WHERE id=? AND submit_date=? ",array($photoId, $submit_date));
	}

	function deleteAllComments($photoId)
	{
		return $this->db->execute("DELETE FROM comments WHERE id=?", array($photoId));
	}

	function deleteComment($photoId, $submit_date)
	{
		return $this->db->execute("DELETE FROM comments WHERE id=? AND submit_date=?", array($photoId, $submit_date));
	}
}
?>
